/**
 * 
 */
package com.example.ad_project;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.nus.iss.ad.dbhelper.DisbursementDBHelper;
import com.nus.iss.ad.model.DisbursementListModel;

/**
 * @author Sachin
 *
 */
public class DisbursmentListActivity extends BaseActivity implements OnItemClickListener{

	DisbursementDBHelper data = new DisbursementDBHelper();
	
	List<DisbursementListModel> dlist = new ArrayList<DisbursementListModel>();
			
	
	@Override
	public void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		//StrictMode.setThreadPolicy(ThreadPolicy.LAX);

		setContentView(R.layout.disbursment_list_activity);

		
		
		/*List<User> userList = new ArrayList<User>();
		
		userList.add(new User("Sachin", "10"));
		userList.add(new User("Sachin", "4"));
		userList.add(new User("Sachin", "1"));
		*/
		
		dlist = data.getDisbursmentModelList();
		
		
		
		
		//   api/getAllCollectionPoints
		
		//List<CollectionPoint> clist = data.getAllCollectionPoints();
		
		
		
		ListView lv = (ListView) findViewById(R.id.listView1);
		lv.setAdapter(new SimpleAdapter(this, dlist, R.layout.disbursment_list_row_layout,
				new String[] { "collectionPointName", "numberofDept"}, new int[] {
						R.id.deptNameTV, R.id.badgeQtyTV}));
		
		lv.setOnItemClickListener(this);
		
	}
	
	public void onSaveAndClear(View v) {

		
		data.confirmDeliveryDisbursment();
		super.onBackPressed();
		
		
	}
	
	@Override
    public void onItemClick(AdapterView<?> av, View v, int position, long id) {
	 
	 
		
		Intent i = new Intent(this, DisbursmentDetailActivity.class);
		i.putExtra("collectionPointId", dlist.get(position).getCollectionPointId());
		startActivity(i);
    }
	
}
